package elitech.vietnam.weatherfashion.tabs.weekly;

import java.util.List;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import elitech.vietnam.weatherfashion.dto.ProductDTO;
import elitech.vietnam.weatherfashion.tabs.today.TodayDetailPagerFragment;

public class WeeklyDetailPagerAdapter extends FragmentStatePagerAdapter {

	private List<ProductDTO> list;
		
	public WeeklyDetailPagerAdapter(FragmentManager fm, List<ProductDTO> list) {
		super(fm);
		
		this.list = list;
	}
	
	@Override
	public Fragment getItem(int arg0) {
		if (arg0==0 && list.size()>1)
			return TodayDetailPagerFragment.init(list.size()-1, list.get(list.size()-1));
		if (arg0==list.size()+1)
			return TodayDetailPagerFragment.init(0, list.get(0));
		if (list.size()>1)
			return TodayDetailPagerFragment.init(arg0-1, list.get(arg0-1));
		return TodayDetailPagerFragment.init(arg0, list.get(arg0));
	}
	@Override
	public int getCount() {
		if (list.size()==1)
			return list.size();
		return list.size() + 2;
	}

	
}
